const app = new Vue({
  el: "#app",
  data: {
     books: [
      {
        id: 1,
        name: '《库里生涯》',
        date: '2021-4-9',
        price: 180,
        count:1
      },
       {
        id: 2,
        name: '《詹姆斯生涯》',
        date: '2021-4-9',
        price: 175,
        count:1
      },
        {
        id: 3,
        name: '《杜兰特生涯》',
        date: '2021-4-9',
        price: 170,
        count:1
      },
         {
        id: 4,
        name: '《哈登生涯》',
        date: '2021-4-9',
        price: 160,
        count:1
      },
    ]
  },
  methods: {
    decrement(index) {
      this.books[index].count--
    },
    increment(index) {
      this.books[index].count++
    },
    removeHandler(index) {
       this.books.splice(index,1)
    }
  },
  computed: {
    totalprice() {
      let totalprice = 0;
      for (let i = 0; i < this.books.length; i++){
        totalprice+=this.books[i].price*this.books[i].count
      }
      return totalprice
    }
  },
  filters: {
    showprice(price) {
       return '￥'+price.toFixed(2)
    }
  }
})